package com.atguigu.spring.pojo;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyTest {
    private Calculator target;

    public ProxyTest(Calculator target) {
        this.target = target;
    }
    public Object getProxy(){
        ClassLoader classLoader = target.getClass().getClassLoader();
        Class<?>[] interfaces = target.getClass().getInterfaces();
        InvocationHandler p = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object result = method.invoke(target, args);
                return result;
            }
        };
        return Proxy.newProxyInstance(classLoader,interfaces,p);
    }
}
